package com.gpframework.module.controller.common;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.util.List;
import java.util.Arrays;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gpframework.common.annotation.Log;
import com.gpframework.common.core.controller.BaseController;
import com.gpframework.common.core.domain.AjaxResult;
import com.gpframework.common.enums.BusinessType;
import com.gpframework.module.common.domain.GpCommonGuidePage;
import com.gpframework.module.common.domain.vo.GpCommonGuidePageVo;
import com.gpframework.module.common.domain.req.GpCommonGuidePageReq;
import com.gpframework.module.common.domain.req.GpCommonGuidePageAdd;
import com.gpframework.module.common.domain.req.GpCommonGuidePageUpdate;
import com.gpframework.module.common.service.IGpCommonGuidePageService;
import com.gpframework.common.utils.poi.ExcelUtil;
import javax.validation.Valid;
import io.swagger.annotations.*;
import com.gpframework.common.core.page.TableDataInfo;
/**
 * @ClassName GpCommonGuidePageController
 * @Author gpframework
 * @Date 2021-12-09
 * @Version 1.0.0
 * @Description 引导页Controller
 */
@Validated
@Api(tags = "引导页")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@SuppressWarnings({"rawtypes","unchecked"})
@RequestMapping("/common/gpCommonGuidePage" )
public class GpCommonGuidePageController extends BaseController {

    private final IGpCommonGuidePageService iGpCommonGuidePageService;

 /**
  * @Description 分页
  * @Author gpframework
  * @Date 2021-12-09
  * @Param gpCommonGuidePage
  * @Return TableDataInfo
 */
    @ApiOperation("列表")
    @PreAuthorize("@ss.hasPermi('common:gpCommonGuidePage:list')")
    @GetMapping("/list")
    public TableDataInfo<GpCommonGuidePageVo> list(GpCommonGuidePageReq gpCommonGuidePageReq)
    {
        startPage();
        QueryWrapper<GpCommonGuidePage> lqw = new QueryWrapper<GpCommonGuidePage>();
        lqw.orderByDesc("gp.update_time");
        gpCommonGuidePageReq.generatorQuery(lqw,true);
        List<GpCommonGuidePageVo> list = iGpCommonGuidePageService.listVo(lqw);
        return getDataTable(list);
    }

    /**
     * @Description 新增
     * @Author gpframework
     * @Date 2021-12-09
     * @Param gpCommonGuidePage
     * @Return TableDataInfo
     */
    @ApiOperation("新增")
    @PreAuthorize("@ss.hasPermi('common:gpCommonGuidePage:add')" )
    @Log(title = "添加引导页" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody GpCommonGuidePageAdd gpCommonGuidePageAdd) {
        GpCommonGuidePage gpCommonGuidePage = Convert.convert(new TypeReference<GpCommonGuidePage>() {}, gpCommonGuidePageAdd);
        return toAjax(iGpCommonGuidePageService.save(gpCommonGuidePage) ? 1 : 0);
    }

    /**
     * @Description 修改
     * @Author gpframework
     * @Date 2021-12-09
     * @Param gpCommonGuidePage
     * @Return TableDataInfo
     */
    @ApiOperation("修改")
    @PreAuthorize("@ss.hasPermi('common:gpCommonGuidePage:edit')" )
    @Log(title = "修改引导页" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody GpCommonGuidePageUpdate gpCommonGuidePageUpdate) {
        GpCommonGuidePage gpCommonGuidePage = Convert.convert(new TypeReference<GpCommonGuidePage>() {}, gpCommonGuidePageUpdate);
        return toAjax(iGpCommonGuidePageService.updateById(gpCommonGuidePage) ? 1 : 0);
    }


    /**
     * @Description 导出
     * @Author gpframework
     * @Date 2021-12-09
     * @Param gpCommonGuidePage
     * @Return TableDataInfo
     */

    @PreAuthorize("@ss.hasPermi('common:gpCommonGuidePage:export')" )
    @Log(title = "导出引导页" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(GpCommonGuidePageReq gpCommonGuidePageReq) {
        QueryWrapper<GpCommonGuidePage> lqw = new QueryWrapper<GpCommonGuidePage>();
        gpCommonGuidePageReq.generatorQuery(lqw,true);
        List<GpCommonGuidePageVo> list = iGpCommonGuidePageService.listVo(lqw);
        ExcelUtil<GpCommonGuidePageVo> util = new ExcelUtil<GpCommonGuidePageVo>(GpCommonGuidePageVo. class);
        return util.exportExcel(list, "gpCommonGuidePage" );
    }

    /**
     * @Description 详情
     * @Author gpframework
     * @Date 2021-12-09
     * @Param gpCommonGuidePage
     * @Return TableDataInfo
     */
    @ApiOperation("详情")
    @PreAuthorize("@ss.hasPermi('common:gpCommonGuidePage:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult<GpCommonGuidePageVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iGpCommonGuidePageService.getVoById(id));
    }



    /**
     * @Description 删除
     * @Author gpframework
     * @Date 2021-12-09
     * @Param gpCommonGuidePage
     * @Return TableDataInfo
     */
    @ApiOperation("删除")
    @PreAuthorize("@ss.hasPermi('common:gpCommonGuidePage:remove')" )
    @Log(title = "删除引导页" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iGpCommonGuidePageService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
